args = -10000
dim ws : set ws = CreateObject("WScript.Shell")
dim varValue : varValue = ws.RegRead("HKEY_CURRENT_USER\Software\MyApp\PADS\ApplicationMode")
'msgbox varValue
dim doc,v
set doc = application.activedocument
v = doc.ActiveView
v.SetExtentsToSelection

dim unit,unit_str
unit = doc.Unit
if unit<>2 then
Application.ExecuteCommand("Global Options")
OptionsDlg.ActiveTab = "Global|General"
OptionsDlg.GlobalDlg.DesignUnits = 0
OptionsDlg.Ok.Click()
end if

Application.ExecuteCommand("Move")	
dim x,y
x =(v.TopLeftX+v.BottomRightX)*0.5
y =(v.TopLeftY+v.BottomRightY)*0.5

args = trim(args)
dim s
s = RegexSplit(args," ")
dim dx,dy
dx = cdbl(s(0))
dy = cdbl(s(1))
dim nx,ny
nx = x + dx
ny = y + dy
'msgbox nx & "," & ny
dim fileroot,tempFile
v.SetExtentsToSelection

fileroot =doc.path
tempFile = fileroot & "\tmp1.mcr"	
dim target
'create file
target = "s"
ocmd = target & " " & nx & " " & ny		
fileContent = fileContent & "Application.ModelessCommand("""& target &""")" & chr(13) & chr(10)
fileContent = fileContent & "DlgModelessCmd.Command = " & chr(34) & ocmd & chr(34) & chr(13) & chr(10)
fileContent = fileContent & "DlgModelessCmd.OnOk()"& chr(13) & chr(10)

'msgbox varValue
select case varValue
	case 0 'placement	
		'msgbox "0"
		ws.RegWrite "HKEY_CURRENT_USER\Software\MyApp\PADS\SPACE",1, "REG_EXPAND_SZ"	
		fileContent = fileContent & "Application.ExecuteCommand(""Complete Move""," & nx & unit_str & ","& ny & unit_str & ")"
	case 1 'routemode
		'msgbox "1"
		ws.RegWrite "HKEY_CURRENT_USER\Software\MyApp\PADS\SPACE",2, "REG_EXPAND_SZ"
	case 2 'draw
		'msgbox "2"
		fileContent = fileContent & "Application.ExecuteCommand(""Add Corner To Drafting""," & nx & unit_str & ","& ny & unit_str & ")"
		ws.RegWrite "HKEY_CURRENT_USER\Software\MyApp\PADS\SPACE",3, "REG_EXPAND_SZ"
	case else 'default 0
		'msgbox "default"
		ws.RegWrite "HKEY_CURRENT_USER\Software\MyApp\PADS\SPACE",0, "REG_EXPAND_SZ"
		
end select

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
set fw = fso.createtextfile(tempFile, True)
fw.write fileContent
fw.close
set fw = nothing
set fso = nothing
Application.RunMacro(tempFile)
set ws = nothing	



Function RegexSplit(expression, delimiter)
	dim isGotoTheEnd : isGotoTheEnd = false
	
	Dim regex, matches, arr(), i
	dim default_delimiter : default_delimiter= "@"
	dim tmpstr :tmpstr = "###!!!###!!!"
	if delimiter=default_delimiter then	
	else
		if instr(expression,default_delimiter)=0 then
			expression = replace(expression,delimiter,default_delimiter)
		else
			if instr(expression,tmpstr)=0 then
				expression = replace(expression,default_delimiter,tmpstr)
				expression = replace(expression,delimiter,default_delimiter)
			else
				msgbox "UnSupport ( conflict string )"
				ReDim arr(0)
				arr(0) = expression
				isGotoTheEnd = true
			end if			
		end if	
	end if
	'Continue	
	if isGotoTheEnd = false then
		dim len_expression :len_expression =len(expression)		
		Set regex = CreateObject("VBScript.RegExp") 
		regex.Pattern = default_delimiter
		regex.Global = True
		Set matches = regex.Execute(expression)
		dim ncount
		ncount = matches.Count+1
		ReDim arr(matches.Count)
		If ncount = 0 Then
			arr(0) = expression			
		else
			dim l_index,u_index,ul_len
			l_index = 0	
			For i = 0 To matches.Count - 1
				u_index = matches(i).FirstIndex-1
				ul_len = u_index-l_index+1
				arr(i) = Mid(expression, l_index, ul_len)
				l_index = matches(i).FirstIndex+1
			next
			'last item
			ul_len=len_expression - l_index
			arr(i) = Mid(expression, l_index, ul_len)
		end if
		'The End
		For i = 0 To UBound(arr)
			arr(cint(i)) = replace(arr(cint(i)),default_delimiter,delimiter)
			'msgbox arr(cint(i))
		Next
	end if	
    RegexSplit = arr
End Function
